package com.lg.partition77;

import java.io.*;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

/**
 * @author `RKC`
 * @date 2022/4/10 15:29
 */
public class P7687CEOI2005_CriticalNetworkLines {

    private static final int N = 100010, M = 2000010;
    private static int[] h = new int[N], e = new int[M], ne = new int[M];
    private static boolean[] bridge = new boolean[M];
    private static int[] dfn = new int[N], low = new int[N], a = new int[N], b = new int[N];
    private static List<Integer> ans1 = new ArrayList<>(N), ans2 = new ArrayList<>(N);
    private static int n, m, k, l, idx = 0, timestamp = 0;

    private static final BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
    private static final BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(System.out));

    public static void main(String[] args) throws IOException {
        String[] ss = reader.readLine().split(" ");
        n = Integer.parseInt(ss[0]);
        m = Integer.parseInt(ss[1]);
        k = Integer.parseInt(ss[2]);
        l = Integer.parseInt(ss[3]);
        ss = reader.readLine().split(" ");
        Arrays.fill(h, -1);
        for (int i = 0; i < k; i++) a[Integer.parseInt(ss[i])] = 1;
        ss = reader.readLine().split(" ");
        for (int i = 0; i < l; i++) b[Integer.parseInt(ss[i])] = 1;
        for (int i = 0; i < m; i++) {
            ss = reader.readLine().split(" ");
            int a = Integer.parseInt(ss[0]), b = Integer.parseInt(ss[1]);
            add(a, b);
            add(b, a);
        }
        tarjan(1, -1);
        writer.write(ans1.size() + "\n");
        for (int i = 0; i < ans1.size(); i++) writer.write(String.format("%d %d\n", ans1.get(i), ans2.get(i)));
        writer.flush();
    }

    private static void tarjan(int u, int edge) {
        dfn[u] = low[u] = ++timestamp;
        for (int i = h[u]; i != -1; i = ne[i]) {
            int v = e[i];
            if (dfn[v] == 0) {
                tarjan(v, i);
                low[u] = Math.min(low[u], low[v]);
                if (low[v] > dfn[u]) {
                    bridge[i] = bridge[i ^ 1] = true;
                    if (a[v] == 0 || b[v] == 0 || a[v] == k || b[v] == l) {
                        ans1.add(u);
                        ans2.add(v);
                    }
                }
                a[u] += a[v];
                b[u] += b[v];
            } else if (edge != (i ^ 1)) {
                low[u] = Math.min(low[u], dfn[v]);
            }
        }
    }

    private static void add(int a, int b) {
        e[idx] = b;
        ne[idx] = h[a];
        h[a] = idx++;
    }
}
